package org.jsola.hr.common;

import com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy;
import lombok.Data;
import org.apache.poi.ss.usermodel.Row;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 手动设置行高
 *
 * @Author zdd
 */

/**
 * 设置表头的自动调整行高策略
 */
public class CellRowHeightStyleStrategy extends AbstractRowHeightStyleStrategy {


    private final List<Style> styleList;

    public CellRowHeightStyleStrategy(List<Style> styleList) {
        this.styleList = styleList;
    }

    @Data
    public static class Style {
        /**
         * 行号;从0开始
         */
        private Integer rowIndex;

        /**
         * 如果excel需要显示行高为15，那这里就要设置为15*20=300
         */
        private Short height;
    }


    @Override
    protected void setHeadColumnHeight(Row row, int relativeRowIndex) {
        if (CollectionUtils.isEmpty(styleList)) {
            return;
        }
        for (Style style : styleList) {
            if (relativeRowIndex == style.getRowIndex()) {
                row.setHeight(style.getHeight());
            }
        }
    }

    @Override
    protected void setContentColumnHeight(Row row, int relativeRowIndex) {
    }

}
